class Admin::Api::CategoriesController < Admin::Api::BaseController

  def index
    @categories = Category.where(depth: 0).all
    items = @categories.map{|c| c.summary_builder}
    api_success(message: '', data: { items: items })
  end

  def create
    @category = Category.new(name: params[:name])
    if @category.save
      api_success(data: { category: @category.summary_builder })
    else
      api_error
    end
  end

  def update
    @category = Category.find_by(id: params[:id])
    if @category.update(name: params[:name])
      api_success
    else
      api_error
    end
  end

end
